/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.							  */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
/*----------------------------------------------------------------------------*/
#ifndef ANALOG_CHANNEL_H_
#define ANALOG_CHANNEL_H_

#include "SensorBase.h"

class AnalogModule;

/**
 * Analog channel class.
 * 
 * Each analog channel is read from hardware as a 12-bit number representing -10V to 10V.
 * 
 * Connected to each analog channel is an averaging and oversampling engine.  This engine accumulates
 * the specified ( by SetAverageBits() and SetOversampleBits() ) number of samples befor returning a new
 * value.  This is not a sliding window average.  The only difference between the oversampled samples and
 * the averaged samples is that the oversampled samples are simply accumulated effectively increasing the
 * resolution, while the averaged samples are divided by the number of samples to retain the resolution,
 * but get more stable values.
 */
class AnalogChannel : public SensorBase
{
public:
	AnalogChannel(unsigned slot, unsigned channel);
	AnalogChannel(unsigned channel);
	virtual ~AnalogChannel();

	AnalogModule *GetModule(void);

	signed short GetValue(void);
	signed int GetAverageValue(void);

	float GetVoltage(void);
	float GetAverageVoltage(void);

	unsigned GetSlot(void);
	unsigned GetChannel(void);

	void SetAverageBits(unsigned bits);
	unsigned GetAverageBits(void);
	void SetOversampleBits(unsigned bits);
	unsigned GetOversampleBits(void);

	unsigned GetLSBWeight(void);
	signed int GetOffset(void);

private:
	void InitChannel(unsigned slot, unsigned channel);
	unsigned m_channel;
	class AnalogModule *m_module;
};

#endif
